const getData = require('../../util/getData')

Page({
  data: {
    musics: []
  },
  async onLoad(options){
    var id = options.id;
   var res=await getData.getMusicContent({id:id})
   this.handleData(res)
  },
  handleData:function(res){
    console.log(res);
    var musics = [];
    var music = res.data.playlist.tracks;
    for (let i = 0; i < music.length; i++) {
      if (i > 30) break;
      var obj = {};
      obj.name = music[i].name;
      obj.author = music[i].ar[0].name;
      obj.pic = music[i].al.picUrl;
      obj.id=music[i].id;
      musics.push(obj);
    }
    console.log(musics);
    this.setData({
      musics,
    })
  },
  handleMusic:function(event){
    var id=event.currentTarget.dataset.id;
    var pic=escape(event.currentTarget.dataset.pic);
    var name=event.currentTarget.dataset.name;
    var author=event.currentTarget.dataset.author;
    wx.navigateTo({
      url:'/pages/music/music?id='+id+'&pic='+pic+'&name='+name+'&author='+author,
    })
  }
})